package com.graduation.sfstore.service;

import com.graduation.sfstore.dao.StoreMapper;
import com.graduation.sfstore.entity.Consumeruser;
import com.graduation.sfstore.entity.OrderForm;
import com.graduation.sfstore.entity.SpeicesSort;
import com.graduation.sfstore.entity.Store;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class StoreService {


    @Resource
    private StoreMapper storeMapper;

    //查询所有库存
    public List<Store> findAllStores(int regionid,int offset,int limit){

        return storeMapper.findAllStores(regionid,offset,limit);
    }

    //查询库存有多少条
    public int selectStoreRows(int regionid) {
        return storeMapper.selectStoreRows(regionid);
    }

    //出入库前查看是否有
    public SpeicesSort findStores(String fishname){
        return storeMapper.findStores(fishname);
    }

    public  List<SpeicesSort> findStoresSort(int offset,int limit){
        return storeMapper.findStoresSort(offset,limit);
    }

    public int findSpeciesSortRows(){
        return storeMapper.findSpeciesSortRows();
    }

    //入总库
    @Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED)
    public int insertfishstore(Store store){
        return storeMapper.insertfishstore(store);
    }

    //入分库
    @Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED)
    public int insertfishstorein(Store store){
        return  storeMapper.insertfishstorein(store);
    }

    //更新总库
    public int updatefishstore(int id ,double weight,int type){
        return storeMapper.updatefishstore(id , weight,type);
    }

    //-更新出库分库
    public int insertfishstoreout(Store store){
        return storeMapper.insertfishstoreout(store);
    }

    public int findMainAmountByName(String region){
        return  storeMapper.findMainAmountByName(region);
    }

    public double findRegionWight(String region){
        return storeMapper.findRegionWight(region);
    }

    public double findRegionOutWight(String region){
        return storeMapper.findRegionOutWight(region);
    }

    public Consumeruser findConsumer(String name, String password){
        return storeMapper.findConsumer(name,password);
    }

    public void insertOrder(OrderForm orderForm){
        storeMapper.insertOrder(orderForm);
    }


}
